home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d21 / dvglue10.arc / UIMSHOW.C < prev    next >
C/C++ Source or Header  |  1988-08-13  |  3KB  |  89 lines

  1. /*======================================================*/
  2. /*  UIMSHOW.C                                           */
  3. /*                                                      */
  4. /* (c) Copyright 1988 Ralf Brown.  All Rights Reserved. */
  5. /*======================================================*/
  6.  
  7. #include <string.h>
  8. #include "tvapi.h"
  9. #include "tvstream.h"
  10. #include "tvui.h"
  11.  
  12. #define HEADER_SIZE 4
  13.  
  14. /*======================================================*/
  15. /*======================================================*/
  16.  
  17. static int default_test_function(OBJECT win,int status,char *fields)
  18. {
  19.    (void) win ;      /* prevent "unused parameter" warnings */
  20.    (void) status ;
  21.    (void) fields ;
  22.    return MA_DONE ;
  23. }
  24.  
  25. /*======================================================*/
  26. /*======================================================*/
  27.  
  28. int pascal UImenu_show(void *menu,int reset,int (*test)(OBJECT,int,char *),char *result)
  29. {
  30.    OBJECT window, kbd ;
  31.    PARMLIST2 parms ;
  32.    char *menu_values ;
  33.    int num_fields = ((int *)menu)[1] ;
  34.    int status, action ;
  35.    int i ;
  36.  
  37. /* start by sending the stream containing the menu setup, and storing away */
  38. /* the created window */
  39.    window = TVwin_new(NIL,((char *)menu)[HEADER_SIZE+6],((char *)menu)[HEADER_SIZE+7]) ;
  40.    TVwin_disallow(window,TV_HSIZE) ;
  41.    TVwin_disallow(window,TV_VSIZE) ;
  42.    parms.num_args = 2 ;
  43.    parms.arg[0] = (DWORD)((char far *)menu) + HEADER_SIZE ;  /* the stream starts here */
  44.    parms.arg[1] = (DWORD) *((int *)menu) ;                   /* and is this long */
  45.    TVsendmsg(WRITE_MSG,TOS,window,(PARMLIST *)&parms) ;
  46.    if (reset)
  47.       TVfld_reset(window) ;
  48. /* now get some storage for the flags indicating whether fields are selected */
  49. /* or not */
  50.    if ((menu_values = (char *)malloc(num_fields+1)) == NULL)
  51.       return NULL ;
  52. /* set up default test function if necessary */
  53.    if (test == NULL)
  54.       test = default_test_function ;
  55. /* create and connect keyboard to window containing menu, and go into field mode */
  56.    kbd = TVkbd_new() ;
  57.    TVkbd_open(kbd,window) ;
  58.    TVkbd_setflags(kbd,KBD_FIELDMODE) ;  /* don't want keyboard active */
  59. /* run through the menu until the user's test function says we're done */
  60.    do {
  61.       TVkbd_read(kbd,menu_values,num_fields+1) ;
  62.       status = TVkbd_status(kbd) ;
  63.       strcpy(result,menu_values) ;   /* copy for return & comparison if changes */
  64.                                      /* are to be made in the selected bits */
  65.       action = (*test)(window,status,menu_values) ;
  66.       if (action & MA_BEEP)
  67.          TVsound(1000,4) ;  /* same note DV uses, but only 1/4 second */
  68.       if (action & MA_RESET)
  69.          TVfld_reset(window) ;
  70.       if (action & MA_SELECT)
  71.          {
  72.          for (i = 0 ; i < num_fields; i++)
  73.             if (result[i] != menu_values[i])
  74.                TVfld_type(window,i+1,(TVqry_type(window,i+1) & ~ F_SELECTED) |
  75.                                      ((menu_values[i] == 'Y') ? F_SELECTED : 0)) ;
  76.          }
  77.       } while ((action & MA_DONE) == 0) ;
  78. /* leave field mode and reconnect default keyboard to task's main window */
  79.    TVkbd_clrflags(kbd,KBD_FIELDMODE) ;
  80.    TVkbd_close(kbd) ;
  81.    TVkbd_setflags(NIL,KBD_ACTIVE) ;
  82. /* and finally clean up and return the results */
  83.    free(menu_values) ;
  84.    TVkbd_free(kbd) ;
  85.    TVwin_free(window) ;
  86.    return status ;
  87. }
  88.  
  89.